home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / set_mode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  2.4 KB  |  114 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: set_mode.c,v 1.1 89/03/17 08:21:20 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/set_mode.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/set_mode.c,v $$Revision: 1.1 $";
  12.  
  13. /* muck with tty modes */
  14.  
  15. #include <sgtty.h>
  16.  
  17. /* set up tty input modes */
  18.  
  19. int set_tty(file)
  20. int file;                /* file descriptor */
  21.    {
  22.    set_mode(file,RAW,ECHO,0);
  23.    }
  24.  
  25. /* setup mouse input modes */
  26.  
  27. int set_mouseio(file)
  28. int file;                /* file descriptor */
  29.    {
  30.    set_mode(file,RAW,ECHO,B1200);
  31.    return(ioctl(file,TIOCEXCL,0));
  32.    }
  33.  
  34. /* reset input tty modes */
  35.  
  36. int reset_tty(file)
  37. int file;                /* file descriptor */
  38.    {
  39.    set_mode(file,ECHO,RAW,0);
  40.    }
  41.  
  42. /*
  43.  *******************************************************************************
  44.  *
  45.  *    Set the terminal mode 
  46.  */
  47.  
  48. static set_mode(file,on,off,speed)
  49. int file;        /* file pointer */
  50. int on;            /* flags to turn on */
  51. int off;        /* flags to turn off */
  52. {
  53.     struct sgttyb buff;
  54.  
  55.     gtty(file,&buff);
  56.     buff.sg_flags |= on;
  57.     buff.sg_flags &= ~off;
  58.     if (speed) 
  59.        buff.sg_ispeed = buff.sg_ospeed = speed;
  60.     stty(file,&buff);
  61.         return(0);
  62. }
  63.  
  64. /* void tty association */
  65.  
  66. void_tty()
  67.    {
  68.    int tty;
  69.  
  70.    tty = open("/dev/tty",2);
  71.    ioctl(tty,TIOCNOTTY,0);
  72.    close(tty);
  73.    }
  74.  
  75. /*********************************************************************/
  76.  
  77. /* save tty modes for getshell */
  78.  
  79. /* place to save tty modes */
  80.  
  81. static int t_ldisc;
  82. static struct sgttyb t_sgttyb;
  83. static struct tchars t_tchars;
  84. static struct ltchars t_ltchars;
  85. static int t_lflags;
  86.  
  87. save_modes(fd)
  88. int fd;            /* fd to save tty modes from */
  89.     {
  90.    ioctl(fd,TIOCGETD,&t_ldisc);
  91.    ioctl(fd,TIOCGETP,&t_sgttyb);
  92.    ioctl(fd,TIOCGETC,&t_tchars);
  93.    ioctl(fd,TIOCGLTC,&t_ltchars);
  94.    ioctl(fd,TIOCLGET,&t_lflags);
  95.     }
  96.  
  97. restore_modes(fd)
  98. int fd;
  99.     {
  100.    ioctl(fd,TIOCSETD,&t_ldisc);
  101.    ioctl(fd,TIOCSETP,&t_sgttyb);
  102.    ioctl(fd,TIOCSETC,&t_tchars);
  103.    ioctl(fd,TIOCSLTC,&t_ltchars);
  104.    ioctl(fd,TIOCLSET,&t_lflags);
  105.     }
  106.  
  107. adjust_mode(disc,flags)
  108. int flags;        /* flags */
  109. int disc;        /* line disc */
  110.     {
  111.    t_ldisc=disc;
  112.    t_sgttyb.sg_flags = flags;
  113.     }
  114.